import typing
from typing import Optional

import PySide6.QtCore
from PySide6.QtGui import QIcon
import PySide6.QtWidgets
from PySide6.QtCore import Qt

from ..LittleWidgetBase import LittleWidgetBase
from .Ui_LWPushButton import Ui_LWPushButton


class LWPushButton(LittleWidgetBase):
    def __init__(
        self, 
        parent: Optional[PySide6.QtWidgets.QWidget] = None, 
        f: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        ################################################
        super().__init__(parent=parent, f=f)
        self._ui = Ui_LWPushButton()
        self._ui.setupUi(self)
        self._propertys.update({
            'text': '',
            'iconPath': '',
        })
        self._ui.pushButton.clicked.connect(self._SlotPushbuttonClicked)

    def UpdateProperty(self, key: 'str', value: typing.Any) -> None:
        super().UpdateProperty(key, value)
        if (key == 'text'):
            self._ui.pushButton.setText(value)
            self._UpdatePropertyValue({key:value})
            self.signalEvent.emit(self.EventTextChanged, self)
        elif (key == 'iconPath'):
            self._ui.pushButton.setIcon(QIcon(value))
            self._UpdatePropertyValue({key:value})

    def _SlotPushbuttonClicked(self) -> None:
        '''
        function:
            当按钮按下的时候做什么
        '''
        self.signalEvent.emit(self.EventClicked, self)

        
